package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.zygh.policeasset.listenter.BasicsImportListener;
import com.zygh.policeasset.listenter.DailyImportListener;
import com.zygh.policeasset.listenter.HardwitImportListener;
import com.zygh.policeasset.listenter.PurchaseImportListener;
import com.zygh.policeasset.listenter.SoftwitImportListener;
import com.zygh.policeasset.pojo.ZipOrRar;
import com.zygh.policeasset.pojo.imports.BasicsImport;
import com.zygh.policeasset.pojo.imports.DailyImport;
import com.zygh.policeasset.pojo.imports.HardwitImport;
import com.zygh.policeasset.pojo.imports.PurchaseImport;
import com.zygh.policeasset.pojo.imports.SoftwitImport;
import com.zygh.policeasset.utils.UnZipAndRarUtil;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/AssetsFilesService.class */
public class AssetsFilesService {
    @Autowired
    AssetsService assetsService;

    public void deZnCompress(ZipOrRar zipOrRar, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Integer selfBuilt) throws Exception {
        Hyperlink link;
        Hyperlink link2;
        String outPath = zipOrRar.getFilePath();
        Sheet[] sheets = UnZipAndRarUtil.readZnExcel(outPath + zipOrRar.getExcelName());
        for (int i = 0; i < sheets.length; i++) {
            if (i == 0) {
                Map<Integer, Object> map = new HashMap<>();
                Sheet sheet = sheets[i];
                int lastRowNum = sheet.getLastRowNum();
                if (lastRowNum > 0) {
                    for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
                        Row row = sheet.getRow(rowNum);
                        for (int cellNum = 0; cellNum < 23; cellNum++) {
                            Cell cell = row.getCell(cellNum);
                            if (cellNum == 0) {
                                UnZipAndRarUtil.getStringValue(cell);
                            }
                            if (!(cell == null || (link2 = cell.getHyperlink()) == null)) {
                                String fileAddr = link2.getAddress();
                                if (!StringUtils.isBlank(fileAddr)) {
                                    map.put(Integer.valueOf(rowNum - 1), outPath + fileAddr);
                                }
                            }
                        }
                    }
                }
                EasyExcel.read(outPath + zipOrRar.getExcelName(), HardwitImport.class, new HardwitImportListener(this.assetsService, projectNo, inputNum, sectionName, sectionId, companyId, type, map, selfBuilt)).sheet(Integer.valueOf(i)).doRead();
            } else if (i == 1) {
                Map<Integer, Object> map2 = new HashMap<>();
                Sheet sheet2 = sheets[i];
                int lastRowNum2 = sheet2.getLastRowNum();
                if (lastRowNum2 > 0) {
                    for (int rowNum2 = 1; rowNum2 <= lastRowNum2; rowNum2++) {
                        Row row2 = sheet2.getRow(rowNum2);
                        for (int cellNum2 = 0; cellNum2 < 22; cellNum2++) {
                            Cell cell2 = row2.getCell(cellNum2);
                            if (cellNum2 == 0) {
                                UnZipAndRarUtil.getStringValue(cell2);
                            }
                            if (!(cell2 == null || (link = cell2.getHyperlink()) == null)) {
                                String fileAddr2 = link.getAddress();
                                if (!StringUtils.isBlank(fileAddr2)) {
                                    map2.put(Integer.valueOf(rowNum2 - 1), outPath + fileAddr2);
                                }
                            }
                        }
                    }
                }
                EasyExcel.read(outPath + zipOrRar.getExcelName(), SoftwitImport.class, new SoftwitImportListener(this.assetsService, projectNo, inputNum, sectionName, sectionId, companyId, type, map2, selfBuilt)).sheet(Integer.valueOf(i)).doRead();
            }
        }
    }

    public void deJcCompress(ZipOrRar zipOrRar, String projectNo, String inputNum, String sectionName, Integer sectionId, Integer companyId, String type, Integer selfBuilt) throws Exception {
        Hyperlink link;
        String outPath = zipOrRar.getFilePath();
        Sheet sheet = UnZipAndRarUtil.readExcel(outPath + zipOrRar.getExcelName());
        Map<Integer, Object> map = new HashMap<>();
        int lastRowNum = sheet.getLastRowNum();
        if (lastRowNum > 0) {
            for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
                Row row = sheet.getRow(rowNum);
                for (int cellNum = 0; cellNum < 19; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (cellNum == 0) {
                        UnZipAndRarUtil.getStringValue(cell);
                    }
                    if (!(cell == null || (link = cell.getHyperlink()) == null)) {
                        String fileAddr = link.getAddress();
                        if (!StringUtils.isBlank(fileAddr)) {
                            map.put(Integer.valueOf(rowNum - 1), outPath + fileAddr);
                        }
                    }
                }
            }
        }
        EasyExcel.read(outPath + zipOrRar.getExcelName(), BasicsImport.class, new BasicsImportListener(this.assetsService, projectNo, inputNum, sectionName, sectionId, companyId, type, map, selfBuilt, DateUtil.now().replaceAll("[[\\s-:punct:]]", ""))).sheet().doRead();
    }

    public void deDaCompress(ZipOrRar zipOrRar, String projectNo, String inputNum, Integer companyId, String type, Integer selfBuilt, String projectType) throws Exception {
        Hyperlink link;
        String outPath = zipOrRar.getFilePath();
        Sheet sheet = UnZipAndRarUtil.readExcel(outPath + zipOrRar.getExcelName());
        Map<Integer, Object> map = new HashMap<>();
        int lastRowNum = sheet.getLastRowNum();
        if (lastRowNum > 0) {
            for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
                Row row = sheet.getRow(rowNum);
                for (int cellNum = 0; cellNum < 19; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (cellNum == 0) {
                        UnZipAndRarUtil.getStringValue(cell);
                    }
                    if (!(cell == null || (link = cell.getHyperlink()) == null)) {
                        String fileAddr = link.getAddress();
                        if (!StringUtils.isBlank(fileAddr)) {
                            map.put(Integer.valueOf(rowNum - 1), outPath + fileAddr);
                        }
                    }
                }
            }
        }
        EasyExcel.read(outPath + zipOrRar.getExcelName(), DailyImport.class, new DailyImportListener(this.assetsService, projectNo, inputNum, companyId, type, map, selfBuilt, projectType, DateUtil.now().replaceAll("[[\\s-:punct:]]", ""))).sheet().doRead();
    }

    public void deCgCompress(ZipOrRar zipOrRar, String projectNo, String inputNum, String type, Integer selfBuilt) throws Exception {
        Hyperlink link;
        String outPath = zipOrRar.getFilePath();
        Sheet sheet = UnZipAndRarUtil.readExcel(outPath + zipOrRar.getExcelName());
        Map<Integer, Object> map = new HashMap<>();
        int lastRowNum = sheet.getLastRowNum();
        if (lastRowNum > 0) {
            for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
                Row row = sheet.getRow(rowNum);
                for (int cellNum = 0; cellNum < 23; cellNum++) {
                    Cell cell = row.getCell(cellNum);
                    if (cellNum == 0) {
                        UnZipAndRarUtil.getStringValue(cell);
                    }
                    if (!(cell == null || (link = cell.getHyperlink()) == null)) {
                        String fileAddr = link.getAddress();
                        if (!StringUtils.isBlank(fileAddr)) {
                            map.put(Integer.valueOf(rowNum - 1), outPath + fileAddr);
                        }
                    }
                }
            }
        }
        EasyExcel.read(outPath + zipOrRar.getExcelName(), PurchaseImport.class, new PurchaseImportListener(this.assetsService, projectNo, inputNum, type, map, selfBuilt)).sheet().doRead();
    }
}